package com.inforich.app.api.controller.area;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.inforich.area.domain.Area;
import com.inforich.common.core.domain.AjaxResult;
import com.inforich.common.utils.poi.ExcelUtil;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description: 地图相关
 * @author: HJM
 * @date: 2022/11/11
 */
@RestController
@RequestMapping("/h5api/map")
public class MapController {

  private static final String URL = "http://mapservices.njghzy.com.cn:84/other/NJCoord/CoordDoJson/CoordDecryptJson";
  private static final String DECRYPTION_84_84P = "WGS84toWGS84P";
  private static final String TOKEN = "90d7cfb84fe57a3e7be5a24aed05e000";

  /**
   * 标准的84坐标系转换为天地图的84P坐标系
   */
  @PostMapping("/WGS84toWGS84P")
  public AjaxResult WGS84toWGS84P(@RequestBody JSONObject param) {
    JSONArray intputInfo = param.getJSONArray("intputInfo");
    if (CollUtil.isEmpty(intputInfo)) {
      return AjaxResult.error("参数不能为空");
    }
    Map<String, Object> body = new HashMap<>();
    body.put("intputInfo", intputInfo.toString());
    body.put("decryption", DECRYPTION_84_84P);
    body.put("njtoken", TOKEN);
    String res = HttpRequest.post(URL).contentType("application/x-www-form-urlencoded").form(body)
        .execute().body();
    return AjaxResult.success(JSONObject.parseObject(res));
  }
}
